using System.Collections.Generic;
using Core;

namespace g_gongjianta
{
    public class SenseSystem : Core.Component, IAwake
    {
        private readonly Dictionary<string, Sense> dict = new();
        private readonly List<Sense> list = new();

        public void Awake()
        {
            var sense = G.Factory.Create<Sense>();
            list.Add(sense);
            dict["1"] = sense;

            sense = G.Factory.Create<Sense>();
            list.Add(sense);
            dict["2"] = sense;

            sense = G.Factory.Create<Sense>();
            list.Add(sense);
            dict["3"] = sense;
        }

        public override void Dispose()
        {
            if (IsDisposed) return;

            foreach (var pair in dict)
            {
                pair.Value.Dispose();
            }

            dict.Clear();

            base.Dispose();
        }

        public Sense GetSense(string code)
        {
            return dict.GetValueOrDefault(code);
        }

        public IReadOnlyList<Sense> GetAll() => list;
    }
}